package vip.xiaonuo.biz.modular.cabinetpermission.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import vip.xiaonuo.biz.core.enums.BizDeviceTypeEnum;
import vip.xiaonuo.common.enums.BizPermissionEnum;

import java.util.Date;
import java.util.List;

@Data
public class BizCabinetDoorPermissionResp {
    private List<Item> cabinetGroupPermAuthorizedList = Lists.newArrayList();
    private List<Item> cabinetGroupPermFrozenList = Lists.newArrayList();

    private List<Item> cabinetInfoPermAuthorizedList = Lists.newArrayList();
    private List<Item> cabinetInfoPermFrozenList = Lists.newArrayList();

    private List<Item> cabinetDoorPermAuthorizedList = Lists.newArrayList();
    private List<Item> cabinetDoorPermFrozenList = Lists.newArrayList();

    public void addCabinetDoorPermission(Item item) {
        if (item == null) return;
        item.setDeviceType(BizDeviceTypeEnum.CABINET_DOOR.name());
        if (BizPermissionEnum.AUTHORIZED.name().equals(item.getPermState())) cabinetDoorPermAuthorizedList.add(item);
        if (BizPermissionEnum.FROZEN.name().equals(item.getPermState())) cabinetDoorPermFrozenList.add(item);
    }

    public void addCabinetInfoPermission(Item item) {
        if (item == null) return;
        item.setDeviceType(BizDeviceTypeEnum.CABINET_INFO.name());
        if (BizPermissionEnum.AUTHORIZED.name().equals(item.getPermState())) cabinetInfoPermAuthorizedList.add(item);
        if (BizPermissionEnum.FROZEN.name().equals(item.getPermState())) cabinetInfoPermFrozenList.add(item);

    }

    public void addCabinetGroupPermission(Item item) {
        if (item == null) return;
        item.setDeviceType(BizDeviceTypeEnum.CABINET_GROUP.name());
        if (BizPermissionEnum.AUTHORIZED.name().equals(item.getPermState())) cabinetGroupPermAuthorizedList.add(item);
        if (BizPermissionEnum.FROZEN.name().equals(item.getPermState())) cabinetGroupPermFrozenList.add(item);
    }

    @Data
    @Builder
    public static class Item {
        @ApiModelProperty(value = "用户Id")
        private String userId;
        @ApiModelProperty(value = "用户account")
        private String account;
        @ApiModelProperty(value = "用户名称")
        private String userName;
        @ApiModelProperty(value = "授权状态")
        private String permState;
        @ApiModelProperty(value = "授权开始时间")
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date permStartTime;
        @ApiModelProperty(value = "授权结束时间")
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date permEndTime;
        @ApiModelProperty(value = "冻结开始时间")
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date frozenStartTime;
        @ApiModelProperty(value = "冻结结束时间")
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date frozenEndTime;
        @ApiModelProperty(value = "扩展说明")
        private String extInfo;
        @ApiModelProperty(value = "授权设备类型")
        private String deviceType;
    }
}
